const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  //起点
  entry: './src/index.js',
  output: {
    filename: 'built.js',
    path: `${__dirname}/build`,
    publicPath: './',
  },
  //loader config
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
      //打包其他资源
      {
        //排除 css,js,html
        exclude: /\.(css|js|html)$/,
        //处理html文件中的img图片（引入img，从而被img-loader
        loader: 'file-loader',
      },
    ],
  },
  plugins: [
    //plugins config
    new HtmlWebpackPlugin({
      //复制html文件，并自动引入打包输出的所有资源
      template: './src/index.html',
    }),
  ],
  mode: 'development',
  //   mode:'production',
  //自动编译，devsever'
  //特点：在内存中编译打包，不会有任何输出
  // webpack-dev-server
  devServer: {
    contentBase: `${__dirname}/build`,
    compress: true,
    port: 3000,
    open: true,
  },
}
